package org.xtense.rcp.editors;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.xtense.rcp.editors.action.DatabaseEditorActionGroup;
import org.xtense.rcp.editors.util.DatabaseTableProvider;
import org.xtense.rcp.util.DocTablelUtil;

public class DatabaseViewer extends EditorPart {
	private Table table;

	@Override
	public void doSave(IProgressMonitor monitor) {
		// do nothing

	}

	@Override
	public void doSaveAs() {
		// do nothing

	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		this.setSite(site);
		this.setInput(input);
	}

	@Override
	public boolean isDirty() {
		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}

	@Override
	public void createPartControl(Composite parent) {
		ViewForm top = new ViewForm(parent, SWT.NONE);
		top.setLayout(new FillLayout());
		TableViewer tv = new TableViewer(top, SWT.SINGLE | SWT.V_SCROLL
				| SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
		table = tv.getTable();
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		TableColumn id = new TableColumn(table, SWT.LEAD);
		id.setText("Document ID");
		id.setWidth(100);
		TableColumn name = new TableColumn(table, SWT.LEAD);
		name.setText("Document Name");
		name.setWidth(150);
		TableColumn storedTime = new TableColumn(table,SWT.LEAD);
		storedTime.setText("Stored Time");
		storedTime.setWidth(250);
		tv.setContentProvider(new DatabaseTableProvider());
		tv.setLabelProvider(new DatabaseTableProvider());
		DocTablelUtil.createDocTable(tv);

		DatabaseEditorActionGroup actionGroup = new DatabaseEditorActionGroup(
				this, tv);

		actionGroup.fillContextMenu();

		top.setContent(tv.getControl());
		
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
